<style scoped>
  .weui-media-box_appmsg .weui-media-box__hd {
    font-size: 12px;
    /*background: #ccc;*/
    color: #fff;
  }
  .weui-media-box_appmsg .weui-media-box__hd .blue {
    background: #296BCC !important;
  }
  .weui-media-box__desc {
    font-size: 12px;
  }
  .weui-media-box__title {
    white-space: normal;
    font-size: 14px;
    margin-bottom: 5px;
    padding: 3px 0;
    display: inline;
  }
  .weui-form-preview__bd {
    text-align: left;
  }

  .weui-form-preview {
    position: relative;
    background-color: #fff;
    margin: 1%;
    border-radius: 5px;
    min-width: 260px;
    border-bottom: 1px solid #eee;
    padding-right: 10px;
  }
  .time {
    position: absolute;
    right: 0;
    top: 0;
    font-size: 10px;
    color: #ccc;
    margin: 3px 0;
  }

  .logimg {
    width: 14px;
    height: 14px;
  }
  .datalist {
    background: #e3e3e3;
    height: 100%;
    overflow: hidden;
  }
  .datalist.nodata {
    font-size: 14px;
    padding: 5px;
  }
  .tit {
    font-size: 12px;
    text-align: left;
    padding: 5px 15px 0 30px;
  }

  .weui-media-box_appmsg {
    display: flex !important;
    font-size: 0;
    padding: 5px;
  }
  .weui-media-box_appmsg .weui-media-box__hd {
    margin-right: 3% !important;
    width: 23%;
    height: 23%;
    white-space: nowrap;
    /*line-height: 23%;*/
    display: inline-block !important;
  }
  .weui-media-box_appmsg .weui-media-box__bd {
    display: inline-block !important;
    width: 71%;
  }
  .weui-media-box__desc {
    overflow: initial;
    line-height: 1.4;
    display: flex;
  }
  .weui-media-box_appmsg .weui-media-box__hd .nodenm{
    width: 50px;
    height: 50px;
    line-height: 50px;
    border-radius: 50%;
    background: #ccc;
    margin: 0 auto;
    text-align: center;
  }
  a:hover {
    cursor: auto;
  }
</style>
<template>
  <div class="logs">
    <!--    <div class="rj-wrap">-->
    <!--      审批记录-->
    <!--      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">-->
    <!--        <img src="../../assets/back.png" style="width: 20px" />-->
    <!--      </a>-->
    <!--    </div>-->
    <!--    <p class="tit" v-show="nodes.length > 0">审批记录</p>-->
    <div style="overflow:auto;overflow-x: hidden;" v-show="nodes.length > 0" id="wrap">
      <div class="weui-form-preview" v-for="(item, index) in nodes">
        <div class="weui-form-preview__bd">
          <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
            <div class="weui-media-box__hd" style="overflow: hidden;">
              <div class="nodenm"  :class="item.status == 2 ? 'blue' : ''">{{item.name}}</div>
            </div>
            <div class="weui-media-box__bd" style="position: relative;">
              <p class="time">{{filterNull(item.logs).createtime}}</p>
              <h4 class="weui-media-box__title" v-if="item.operators.length <= 1" v-for="(oper, i) in item.operators">{{oper != null ? oper.realname : ''}}</h4>
              <h4 class="weui-media-box__title" v-if="item.operators.length > 1"><span v-for="(oper2, i) in item.operators">{{oper2 != null ? oper2.realname : ''}}<i v-show="i+1 != item.operators.length"> / </i></span></h4>
              <p class="weui-media-box__desc">{{filterNull(item.logs).description}}</p>
              <div class="exp uploaderFiles" style="display: inline-block;padding-top: 5px;" v-if="item.logs != null && item.logs.imgs.length > 0">
                <viewer :images="item.logs.imgs">
                  <img class="logimg" style="padding-right: 5px;cursor: pointer;" v-for="(image, index) in item.logs.imgs" :key="image.guid"  alt="" onerror="javascript:this.src='../../../static/common/image/pic.png';this.onerror = null" :src="image.url + '.png'" >
                </viewer>
              </div>
              <template  v-if="item.appendRemark != ''" v-for="(remark, index) in packIt(item.appendRemark)">
                <p class="weui-media-box__desc" style="border-top: 0.5px solid #eee;padding-top: 8px;">{{remark.remark}}</p>
                <div class="icontbox contbox-txt" style="padding-bottom: 5px;">
                  <!--                  <h4 class="weui-media-box__title contbox-h4">{{remark.operator}}</h4>-->
                  {{remark.appendDate}}
                </div>
              </template>
            </div>
          </a>
        </div>
      </div>
    </div>
    <div v-show="isReady && nodes.length <= 0 && sellformpid == undefined" class="datalist nodata">没有审批记录哦~</div>
  </div>
</template>

<script>
  import {getSaleFlowNodes} from "@/api/public";

  import 'viewerjs/dist/viewer.css'
  import Viewer from 'v-viewer'
  import Vue from 'vue'
  Vue.use(Viewer)

  export default {
    name: 'SalesOperationLogs2',
    data () {
      return {
        nodes: [],
        nodesHtml: '',
        userid: localStorage.userid,
        username: localStorage.username,
        matchedRmrks: [],
        isReady: false
      }
    },
    props: [
      'orderid',
      'srguid',
      'departid',
      'sellformpid',
      'sellformpcode',
      'nodeid'

    ],
    mounted() {
      this.getOperatelogs();
      $('#wrap').on('click', '.logimg', function () {
        let num = $(this).parent().children().length;
        let imgArr = [];
        for (var i=0; i<num; i++) {
          imgArr.push($(this).parent().find('.logimg').eq(i).data('img'));
        }
        let index = $(this).index();
        let pb2 = $.photoBrowser({
          items: imgArr,
          initIndex: index
        });
        pb2.open();
      });
    },
    watch: {
      'orderid': function (val) {
        this.getOperatelogs();
      },
      'srguid': function (val) {
        this.getOperatelogs();
      },
      'departid': function (val) {
        this.getOperatelogs();
      },
    },
    methods: {
      getOperatelogs: function (id) {
        if (this.orderid == undefined || this.departid == undefined) return;
        getSaleFlowNodes({guid: this.orderid, srguid: this.srguid, departid: this.departid})
          .then(response => {
            this.isReady = true;
            if (response.code == '200') {
              this.nodes = response.data;
              let pendNodes = this.nodes.filter(item => {
                return item.status == 2;
              })
              this.initNodesSelect(pendNodes);
              // this.warnAppendRemark(this.nodes);
            } else {
              //this.toastText('获取审批记录失败');
            }
          });
      },
      packIt: function(obj) {
        if (obj != '') {
          return JSON.parse(obj);
        } else {
          return [];
        }
      },
      warnAppendRemark: function(nodes) {
        let that = this;
        nodes.some(item => {
          if (item.appendRemark != '') {
            let appendRemark = JSON.parse(item.appendRemark);
            let matchedRmrks = appendRemark.filter(remark => {
              return remark.toNodeid == that.nodeid;
            });
            that.matchedRmrks = matchedRmrks;

            if (matchedRmrks.length > 0) {
              matchedRmrks.filter((rm, i) => {
                if (i == 0) {
                  that.toastText3(rm.operator + '：' + rm.remark);
                } else {
                  setTimeout(function () {
                    that.toastText3(rm.operator + '：' + rm.remark);
                  }, 3000)
                }
              })
            }
          }
        })
      },
      initNodesSelect: function (arr) {
        let content = '<div class="cellgroup"> <div class="weui-cell weui-cell_select fir"> <div class="weui-cell__hd"><label class="weui-label">提醒对象</label></div> <div class="weui-cell__bd"> <select class="weui-select" name="" id="tonode"> <option value="">请选择</option>';
        for (let i=0; i<arr.length; i++) {
          content += '<option value="'+ arr[i].guid +'">'+ arr[i].name +'</option>';
        }
        content += '</select> </div> </div> <div class="weui-cell"> <div class="weui-cell__hd"><label class="weui-label">信息</label></div> <div class="weui-cell__bd"> <textarea id="remark" class="weui-textarea" name="" placeholder="请输信息内容" rows="2"></textarea> </div> </div> </div>';
        this.nodesHtml = content;
      },
      filterNull: function (obj) {
        return obj != null ? obj : {};
      }
    }
  }
</script>
